package com.fresh.controller;

import com.fresh.common.ResponseResult;
import com.fresh.service.SecKillService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/seckill")
public class SecKillController {

    @Autowired
    private SecKillService secKillService;


    @PostMapping("/rush")
    public ResponseResult rush(@RequestParam("goodsId") Integer goodsId, @RequestParam("address")String address, HttpServletRequest httpServletRequest){
        //TODO 秒杀逻辑
        boolean flag = secKillService.rushGoods(goodsId,1,address,httpServletRequest);
        if (flag){
            return ResponseResult.success();
        }else {
            return ResponseResult.error(601,"抢购失败");
        }
    }
}
